import java.util.ArrayList;
import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Lily
 * Date: 2024-09-22
 * Time: 19:14
 */
public class test_2 {
    public ArrayList<Integer> intersection(ArrayList<Integer> nums1, ArrayList<Integer> nums2) {
        ArrayList<Integer> ret = new ArrayList<>();
        int[] number1 = new int[1001];
        for (int x : nums1) {
            number1[x] = 1;
        }
        for (int x : nums2) {
            if (number1[x] == 1) {
                ret.add(x);
                number1[x]--;
            }
        }
        return ret;
    }
}
